package ru.ifmo.swing;

import javax.swing.*;
import java.awt.*;
import java.util.Collections;
import java.util.List;

/**
 * @author avhaliullin
 */
public class Panel extends JPanel {
    {
        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    }

    public void setHorizontal(boolean isHorizontal) {
        setLayout(new BoxLayout(this, isHorizontal ? BoxLayout.X_AXIS : BoxLayout.Y_AXIS));
    }

    public void setTitle(String title) {
        setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder(title),
                BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    }

    public void setComponentsList(List<JComponent> components) {
        removeAll();
        for (JComponent component : components) {
            add(component);
        }
    }

    public void setComponent(JComponent component) {
        setComponentsList(Collections.singletonList(component));
    }

    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        for (Component component : getComponents()) {
            component.setEnabled(enabled);
        }
    }
}
